package parion.testframeanimation;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
	ImageView imageView;
	Button start, stop;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		imageView = (ImageView)findViewById(R.id.imageView1);
		Button start = (Button)findViewById(R.id.start);
		Button stop = (Button)findViewById(R.id.stop);
		start.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AnimationDrawable anim = (AnimationDrawable)imageView.getDrawable();
				anim.start();
			}
		});
		
//		public void onWindowFocusChanged(boolean hasFocus){
//		if(hasFocus){
//			AnimationDrawable anim = (AnimationDrawable)imageView.getDrawable();
//			anim.start();
//		}else{
//			AnimationDrawable anim = (AnimationDrawable)imageView.getDrawable();
//			anim.stop();
//		}
//		}
		
		
		stop.setOnClickListener(new View.OnClickListener() {
		
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AnimationDrawable anim = (AnimationDrawable)imageView.getDrawable();
				anim.stop();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
